package co.yixiang.modules.qeCode.rest;

import co.yixiang.annotation.AnonymousAccess;
import co.yixiang.modules.qeCode.enums.QrCodeActionEnum;
import co.yixiang.modules.qeCode.enums.operation.res.QrCodeResult;
import co.yixiang.modules.qeCode.param.QrCodeParam;
import co.yixiang.modules.system.util.BeanUtils;
import co.yixiang.utils.QrCodeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 二维码扫码模块
 * </p>

 */
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/api/qrCode")
@Api(value = "二维码扫码模块", tags = "商城:二维码扫码模块", description = "二维码扫码模块")
public class QrCodeController {

	@AnonymousAccess
	@GetMapping
	@ApiOperation(value = "二维码扫码", notes = "二维码扫码")
	public ResponseEntity<QrCodeResult<?, ?>> qeCodeScan(QrCodeParam qrCodeParam) {
		String action = BeanUtils.notBlank(qrCodeParam.getAction(), "扫码失败, 扫码参数异常");
		QrCodeActionEnum qrCodeActionEnum = BeanUtils.notNull(QrCodeActionEnum.valueOf(action), "扫码失败, 扫码参数异常");
		return ResponseEntity.ok(qrCodeActionEnum.action(qrCodeParam));
	}


	@AnonymousAccess
	@GetMapping(value = "/getQrCode")
	@ApiOperation(value = "获取二维码", notes = "获取二维码")
	public ResponseEntity<Object> getQrCode(QrCodeParam qrCodeParam) {
		return ResponseEntity.ok(QrCodeUtils.getActionWebQrCodeUrl(qrCodeParam.getKey(), qrCodeParam.getAction()));
	}

}

